package com.mobilesafe.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
/**
 * 手机重启的广播接受者
 *              一旦手机重启发现sim串号不同，则向安全号码发送短信提示报警
 * @author yaoweber
 *
 */
public class BootCompleteReceiver extends BroadcastReceiver {
	private static final String TAG = "BootCompleteReceiver";
	private SharedPreferences sp;

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		Log.i(TAG, "重启完毕");
		// 判断手机是否处于保护状态
		sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
		boolean isprotecting = sp.getBoolean("isprotecting", false);
		if (isprotecting) {
			TelephonyManager manager = (TelephonyManager) context
					.getSystemService(Context.TELEPHONY_SERVICE);
			String currentsim = manager.getSimSerialNumber();
			String realsim = sp.getString("sim", "");
			if (!(currentsim.equals(realsim))) {// sim 卡串号不同
				// 发送报警短信
				Log.i(TAG, "发送报警短信");
				SmsManager sms = SmsManager.getDefault();
				String destinationAddress = sp.getString("safenumber", "");
				sms.sendTextMessage(destinationAddress, null,
						"sim卡发生了改变,手机可能被盗", null, null);

			}
		}

	}

}
